#pragma once
#include "afxwin.h"
#include "afxcmn.h"

#include "Business/Policy/OneLegArbitrageBusiness.h"
#include "Business/QueueContext.h"
#include "Utils/FastBlockQueue.h"

class ThreadManager;

class COneLegArbitrageBusinessDlg : public CDialog
{
	DECLARE_DYNAMIC(COneLegArbitrageBusinessDlg)

public:
	COneLegArbitrageBusinessDlg(ThreadManager& threadManager);   // standard constructor
	virtual ~COneLegArbitrageBusinessDlg();

// Dialog Data
	enum { IDD = IDD_ONE_LEG_ARBITRAGE_DLG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	virtual void OnCancel();

	afx_msg void OnBnClickedBtnAdd();
	afx_msg void OnBnClickedBtnModify();
	afx_msg void OnCbnSelchangeMajorCombo();
	afx_msg void OnLvnItemchangedBusinessList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnKeydownBusinessList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTimer(UINT_PTR nIDEvent);

	DECLARE_MESSAGE_MAP()
private:
	CComboBox m_majorCombo;
	CComboBox m_minorCombo;
	CEdit m_changeUnitCountEdit;
	CEdit m_marketCountEdit;
	CEdit m_maxTimeEdit;
	CListCtrl m_businessList;

private:
	void InitBusinessList();
	OneLegArbitrageArguemnt GetArgument();
	void InitComboData(int majorContract);
	void InitControlText(OneLegArbitrageArguemnt const& argument);
	void InitComboSel(CComboBox& combo,int contract);
	bool Validate(OneLegArbitrageArguemnt const& argument) const;
	void InitMinorCombo(UINT majorContract);
	OneLegArbitrageBusiness* GetSelectedBusiness();
	int GetCommandType(WORD key);
	void OnCommand(Command const &cmd);
	OneLegArbitrageBusiness* AddBusiness(OneLegArbitrageArguemnt const& argument);
	int GetBusinessIndex(OneLegArbitrageBusiness* business) const;
	void InsertBusiness(OneLegArbitrageBusiness* business);
	void UpdateBusiness(int index,OneLegArbitrageArguemnt const& argument);
	void HandlerShortcuts(int index, WORD key);
	void PushPendingMarket(int contract,Direction::TYPE direction,int price,int quantity);
	ThreadManager& m_threadManager;
	FastBlockQueue::FastBlockQueuePtr m_uiQueue;
	QueueContext m_queueContext;
	int m_notifyColumnPosition;
	std::map<OneLegArbitrageBusiness*,int> m_businessIndexMap;
};
